package string.leetcode.easy;

/**
 * @author bruin_du
 * @description 有效的回文
 * @date 2022/8/9 20:15
 **/
public class OfferII018_IsPalindrome {
    public boolean isPalindrome(String s) {
        int begin = 0, end = s.length() - 1;
        s = s.toLowerCase();
        char[] arr = s.toCharArray();
        while (begin <= end) {
            while (begin <= end && !Character.isLowerCase(arr[begin]) && !Character.isDigit(arr[begin])) {
                begin++;
            }
            while (begin <= end && !Character.isLowerCase(arr[end]) && !Character.isDigit(arr[end])) {
                end--;
            }
            if (begin <= end && arr[begin] != arr[end]) {
                return false;
            }
            begin++;
            end--;
        }
        return true;
    }
}
